<?php
/**
 * 监控
 */
namespace app\model;

use think\Model;
use app\model\Chain;

class MonitorModel extends Model
{
	protected $name = 'monitor';
	/**
	 * 监控列表
	 *
	 */
	public function GetList($where){
		$MonitorModel=new MonitorModel;
		$result=$MonitorModel->field('id,name,identification,type,updatetime')->where($where)->order('id desc')->paginate()->toArray();
		foreach ($result['data'] as &$val){
			$val['updatetime']=date('Y-m-d H:i:s',$val['updatetime']);
		}
		return $result;
	}
	/**
	 * 监控详情
	 *
	 */
	public function GetDetail($param){
		$where=" status=1 ";
		if($param['identification']){
			$where.=" and identification='{$param['identification']}' ";
		}
		if($param['type']){
			$where.=" and type='{$param['type']}' ";
		}
		if($param['user_id']){
			$where.=" and user_id='{$param['user_id']}' ";
		}
		$MonitorModel = MonitorModel::where($where)->find();
		return $MonitorModel;
	}
	/**
	 * 添加
	 *
	 */
	public function AddData($param){
		$MonitorModel = new MonitorModel;
		$param['createtime']=time();
		$param['updatetime']=time();
		$field=['user_id','name','identification','type','createtime','updatetime','project_id'];
		$MonitorModel->allowField($field)->save($param);
		$id=$MonitorModel->id;
		
		
		return $id;
	}
	/**
	 * 修改禁用状态
	 *
	 */
	public function UpdateStatus($id){
		$MonitorModel = MonitorModel::find($id);
		$MonitorModel->status=$MonitorModel->status==1?0:1;
		$MonitorModel->save();
		return true;
	}
	/**
	 * 删除
	 *
	 */
	public function Del($param){
		$update=[];
		foreach($param as $val){
			$update[]=['id'=>$val,'status'=>-1,'deletetime'=>time()];
		}
		if(!empty($update)){
			$MonitorModel = new MonitorModel;
			$MonitorModel->saveAll($update);
		}
		return true;
	}
}